<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="root">
    <h2>当前的n的值是<span v-text="n"></span></h2>
    <h2>放大十倍的n的值是<span v-big-number="n"></span></h2>
    <button @click="n++">点击n+1</button>
    <hr>
    <input type="text" v-fbind:value="n">
</div>
<script src="../js/vue.js"></script>
<script>
    Vue.config.productionTip = false//阻止vue启动时产生提示
    //全局自定义指令
    /*Vue.directive('fbind2',{
        //指令与元素成功绑定时
        bind(element,binding){
            element.value=binding.value;
        },
        //指令所在元素被插入页面时
        insert(element,binding){
            element.focus();
        },
        //指令所在的模板被重新解析时
        update(element,binding){
            element.value=binding.value;
        },
    })*/
    /* VUe.directive('big-number',function(element,binding){/!*元素，绑定*!/
         console.log('big')
         console.log('big',this)//注意此处的this时window
         console.log(element,binding.value)
         element.innerText=binding.value*10;
     })*/
    new Vue({
        el: "#root",
        data: {//数据
            name: '',
            n: 1
        },
        methods: {//方法

        },
        computed: {//计算

        },
        watch: {//监视

        },
        directives: {
            //指令和元素成功绑定是会被调用，指令所在的模板被重新解析时也会被调用
            //完整写法
            'big-number': function (element, binding) {/*元素，绑定*/
                console.log('big')
                console.log('big', this)//注意此处的this时window
                console.log(element, binding.value)
                element.innerText = binding.value * 10;
            },

            fbind: {
                //指令与元素成功绑定时
                bind(element, binding) {
                    element.value = binding.value;
                },
                //指令所在元素被插入页面时
                insert(element, binding) {
                    element.focus();
                },
                //指令所在的模板被重新解析时
                update(element, binding) {
                    element.value = binding.value;
                },

            }

        }
    })
</script>
</body>
</html>